package usually;
//338. 比特位计数
public class Num338_countBits {
    public int[] countBits(int n) {
        int []ret = new int[n+1];
        ret[0] = 0;
        for (int i = 1  ; i < n+1; i++) {
            ret[i] = bit1(i);
        }
        return ret;


    }
    static int bit1(int n){
        int count = 0;
        while (n != 0){
            n = n & n-1;
            count++;
        }
        return count;
    }
}
